package com.wwwzh.himalayafm.fragment.disfragment.anchorfragment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.wwwzh.himalayafm.R;
import com.wwwzh.himalayafm.callback.IsScrollButtonListener;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */

public class Anchoradapter extends RecyclerView.Adapter<Anchoradapter.ViewHolder> {
    private Context context;
    private IsScrollButtonListener listener;
    private List<AnchorEntity.AnchorChild> list;

    public Anchoradapter(Context context, IsScrollButtonListener listener) {
        this.listener = listener;
        this.context = context;
        list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_anchor_item, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (list.get(position).getList() != null) {
            holder.hoster_title.setText(list.get(position).getTitle());
            holder.hoster_nickname.setText(list.get(position).getList().get(0).getNickname());
            holder.hoster_nickname2.setText(list.get(position).getList().get(1).getNickname());
            holder.hoster_nickname3.setText(list.get(position).getList().get(2).getNickname());
            Picasso.with(context).load(list.get(position).getList().get(0).getSmallLogo()).into(holder.hoster_iamge);
            Picasso.with(context).load(list.get(position).getList().get(1).getSmallLogo()).into(holder.hoster_iamge2);
            Picasso.with(context).load(list.get(position).getList().get(2).getSmallLogo()).into(holder.hoster_iamge3);
        }
        if (position == list.size() - 1) {
            listener.isScrollbutton();
        }
    }
    public void addAll(Collection<? extends AnchorEntity.AnchorChild> collection) {
        int size = list.size();
        list.addAll(collection);
        notifyItemRangeInserted(size, collection.size());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView hoster_title;
        private TextView hoster_nickname;
        private TextView hoster_nickname2;
        private TextView hoster_nickname3;
        private ImageView hoster_iamge;
        private ImageView hoster_iamge2;
        private ImageView hoster_iamge3;

        public ViewHolder(View itemView) {
            super(itemView);
            hoster_title = ((TextView) itemView.findViewById(R.id.hoster_title));
            hoster_nickname = ((TextView) itemView.findViewById(R.id.hoster_nickname));
            hoster_nickname2 = ((TextView) itemView.findViewById(R.id.hoster_nickname2));
            hoster_nickname3 = ((TextView) itemView.findViewById(R.id.hoster_nickname3));
            hoster_iamge = ((ImageView) itemView.findViewById(R.id.hoster_image));
            hoster_iamge2 = ((ImageView) itemView.findViewById(R.id.hoster_image2));
            hoster_iamge3 = ((ImageView) itemView.findViewById(R.id.hoster_image3));
        }
    }

}
